<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
   
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
    <link rel="stylesheet" href="../css/newEnvsion.css" type="text/css" />
	<link rel="stylesheet" type="text/css" href="../extjs/resources/css/ext-all.css">	
    <script type="text/javascript" src="../extjs/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="../extjs/ext-all-debug.js"></script>
    
    
    <script type="text/javascript">
    	Ext.onReady(function(){
    		var registerForm = new Ext.form.FormPanel({
				id:'registerF',
				defaultType:'textfield',
				labelAlign:'right',
				labelWidth:200,
				frame:true,
				defaults:{
					allowBlank:false
				},
				items:[
				{id:'userid',name:'user.userid',fieldLabel:'账号名(字母，数字，下划线组成)',blankText:'不能为空',emptyText:'必填',anchor:'98%'},
				{id:'password1',name:'user.password',fieldLabel:'密码(字母，数字，符号组成)',blankText:'不能为空',inputType:'password',emptyText:'必填',anchor:'98%',maxLength:10},
				{id:'password2',fieldLabel:'确认密码',blankText:'不能为空',inputType:'password',anchor:'98%',emptyText:'必填',maxLength:10},
				{id:'username',name:'user.username',fieldLabel:'姓名',blankText:'不能为空',emptyText:'必填',anchor:'98%'},
				{id:'email',name:'user.email',fieldLabel:'邮箱',blankText:'不能为空',emptyText:'必填',anchor:'98%'}
				]		
			});
    		var win = new Ext.Window({
    			title:'注册',
    			id:'registerForm',
    			
				
    			closable:true,
				collapsible:false,
				resizable:false,
				defaults:{
					border:false
				},
				buttonAlign:'center',
				buttons:[
				{text:'注册',type:'submit',id:'sb',height:100,handler:register},
				{text:'重置',height:100,handler:function(){
					Ext.getCmp('registerF').form.reset();
				}}	
				],
				items:[
					registerForm
				]
    		});
    		win.show();
		});
		
		function register(){
			var loginForm = Ext.getCmp("registerF");
			var pas1 = Ext.getCmp("password1").getValue();
			var pas2 = Ext.getCmp("password2").getValue();
			var userid = Ext.getCmp("userid").getValue();
			var email = Ext.getCmp("email").getValue();
			var userfilter = /^[a-zA-Z]\w{1,20}$/
			var pasfilter = /^.{6,}$/
			if(!userfilter.test(userid)){
				Ext.Msg.alert("用户名只能有字母，数字，下划线组成，且第一个为字母");
				return;
			}
			if(!pasfilter.test(pas1)){
				Ext.Msg.alert("密码长度大于6位，由字母，数字，常用符号组成");
				return;
			}
			Ext.Ajax.request({
				url:'login/checkuserid.action',
				params:{
					userid:userid
				},
				success:function(response,options){
					var responseArray = Ext.util.JSON.decode(response.responseText); 
					if(responseArray.msg == "ERROR"){
						alert('用户名存在');
						return;
					}  
					if(pas1 != pas2){
						alert("两次密码不同");
						return;
					} 
					var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 
					if(!filter.test(email)){
						alert("邮箱格式不正确");
						return;
					}
					if(loginForm.form.isValid()){
						loginForm.form.submit({
							waitMsg:'正在进行验证，请稍后',
							url:'login/register.action',
							method:'POST',			
							//call back
							success:function(form,action){
								if(action.result.msg == 'OK'){
									alert("注册成功");
									window.location.href="../login.html";
								}else if(action.result.msg == 'ERROR'){
									alert("错误");
								}
							},
							failure:function(form,action){	
								switch (action.failureType) {    
				                            case Ext.form.Action.CLIENT_INVALID:    
				                                Ext.Msg.alert('错误提示', '表单数据非法请核实后重新输入！');    
				                                break;    
				                            case Ext.form.Action.CONNECT_FAILURE:    
				                                Ext.Msg.alert('错误提示', '网络连接异常！');    
				                                break;    
				                            case Ext.form.Action.SERVER_INVALID:    
				                               Ext.Msg.alert('错误提示', "您的输入用户信息有误，请核实后重新输入！");    
				                                   
				                            }  
							}
						});
						}
				}
			});
			
			
			
		}
    	
    </script>
  </head>
  
  <body>
  <div id="wrap">
  	<div id="main">
  	</div>
  </div>
  </body>
</html>